<?php
    /******************************************************************************
     *    Copyright ZhangYue
     * Author:                Quinn Xu
     * Description:           
     * Want argument:         
     * Output:                
     * Create Date:           2012-12-18
     *****************************************************************************/
    class chengjiguanli
    {
        private $shujubiao = 'chengji';
        
		//获取班级列表
        public function huoqubanjiliebiao()
        {
            global $db;
            $query = "SELECT banji FROM chengji GROUP BY banji";
            return $db->query($query);
        }
        
		//获取年级总人数
        public function huoquzongrenshu()
        {
            global $db;
            $query = "SELECT count(*) as zongrenshu FROM {$this->shujubiao} WHERE xingming<>''";
            return $db->query($query);
        }
        
        //获取层次人数,优化后的
        public function huoqugebancengcirenshu($model)
        {
            global $db;
            $query = "SELECT banji,COUNT(*) as renshu FROM {$this->shujubiao} WHERE xingming<>'' AND nianjimingci>{$model->getQishimingci()} AND nianjimingci<={$model->getJiezhimingci()} GROUP BY banji ORDER BY banji ASC";
            $result = $db->query($query);
            return $result;
        }
        
		//获取指定班级指定层次人数
        public function huoqucengcirenshu($model)
        {
            global $db;
            $query = "SELECT count(*) as zongrenshu FROM {$this->shujubiao} WHERE xingming<>'' AND nianjimingci>{$model->getQishimingci()} AND nianjimingci<={$model->getJiezhimingci()} AND banji={$model->getBanji()}";
            try{
                $result = $db->query($query);
            }
            catch (Exception $e)
            {
                $result = null;
            }
            return $result;
        }
        
		//获取指定层次最末名次
        public function huoquzuihoumingci($model)
        {
            global $db;
            $query = "SELECT nianjimingci FROM {$this->shujubiao} ORDER BY nianjimingci ASC LIMIT {$model->getJiezhimingci()},1";
            return $db->query($query);
        }
    }
?>